﻿<Window x:Class="WpfStateValidation.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Local="clr-namespace:WpfStateValidation"
    Title="WPF State Validation" Height="200" Width="300">
	<Window.Resources>
		<Style TargetType="{x:Type TextBox}">
			<Style.Triggers>
				<Trigger Property="Validation.HasError" Value="true">
					<Setter Property="ToolTip"
                Value="{Binding RelativeSource={RelativeSource Self}, 
                       Path=(Validation.Errors)[0].ErrorContent}"/>
				</Trigger>
			</Style.Triggers>
		</Style>
	</Window.Resources>
	<Window.DataContext>
		<Local:User Username="Mike" Email="a@b.com" Age="30" />
	</Window.DataContext>
	<StackPanel Margin="10">
		<!-- Username -->
		<StackPanel Orientation="Horizontal">
			<TextBlock Text="Username: " />
			<TextBlock Text="{Binding Path=Username}" Foreground="Gray"/>
		</StackPanel>
		<TextBox Text="{Binding Path=Username, ValidatesOnDataErrors=True}" />
		<!-- Email -->
		<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
			<TextBlock Text="Email: " />
			<TextBlock Text="{Binding Path=Email}" Foreground="Gray"/>
			<TextBlock Text=" (update on PropertyChanged)" Foreground="DarkRed" />
		</StackPanel>
		<TextBox Text="{Binding Path=Email, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" />
		<!-- Age -->
		<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
			<TextBlock Text="Age: " />
			<TextBlock Text="{Binding Path=Age}" Foreground="Gray"/>
		</StackPanel>
		<TextBox Text="{Binding Path=Age, ValidatesOnDataErrors=True}" />
	</StackPanel>
</Window>